package com.itholmes.controller;

import com.itholmes.config.IPSstatic;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
public class Consumer01 {

    @Resource
    RestTemplate restTemplate;

    @GetMapping("/consumer/pay")
    public String testZk(HttpServletRequest request){

//        第一种:通过servletContext来获取可以。
//        ServletContext servletContext = request.getServletContext();
//        List<String> zk = (List<String>)servletContext.getAttribute("zk");
//        String randomString = MathRandom.getRandomString(zk);

//        第二种：通过一个专门的类，设置static变量获取(推荐方便！)
        String lBforIP = IPSstatic.getLBforIP();

        //我要拿到zookeeper那边的信息，放到这里
        String forObject = restTemplate.getForObject("http://" + lBforIP + "/provider", String.class);
        return forObject;
    }

}
